package mm.util;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public class ActionHelper {

	public static String readPageContent(String pagePath) {
		pagePath=Constants.WEB_PATH+"/WEB-INF/pages"+pagePath;
		LOG.debug("Reading file: "+pagePath);
		InputStream is=null;
		BufferedReader reader =null;
		StringBuffer sb=new StringBuffer();
		try{
			is = new FileInputStream(new File(pagePath));
			reader = new BufferedReader(new InputStreamReader(is));
			char[] buf = new char[1024];
			for(int numRead=0; (numRead=reader.read(buf)) != -1; ){
				String readData = String.valueOf(buf, 0, numRead);
				sb.append(readData);
			}
		}catch(IOException e){
			LOG.error(e);
			return null;
		}finally{
			if(reader!=null)
				try {
					reader.close();
				} catch (IOException e) {
					LOG.error(e);
				}
			if(is!=null)
				try {
					is.close();
				} catch (IOException e) {
					LOG.error(e);
				}
		}
		return sb.toString();
	}

}
